import axios from 'axios';
import { ethers } from 'ethers';

const BASE_URL = 'http://localhost:3000/api/v1';

async function testI18nMessages() {
    console.log('🌍 测试 i18n 多语言消息...\n');

    // 使用ethers进行离线签名
    // 注意：此处仅用于测试，私钥请勿用于生产环境

    // 测试钱包私钥（仅测试用）
    const testPrivateKey = '9b225c646ba70c3e57756bdc8e30d6ac0fa5b614ed9baae00e92740713894eb2';
    const wallet = new ethers.Wallet(testPrivateKey);

    // 构造待签名消息
    const message = 'Welcome to RWA Platform! Please sign this message to authenticate.';

    // 进行离线签名
    const signature = await wallet.signMessage(message);

    // 测试中文
    console.log('📝 测试中文 (zh):');
    try {
        const response = await axios.post(`${BASE_URL}/auth/wallet-login?lang=zh`, {
            walletAddress: wallet.address,
            message: message,
            signature: signature,
            chainId: 1,
            fullName: 'Test User'
        });
        console.log(`  状态码: ${response.status}`);
        console.log(`  响应语言: ${response.headers['content-language']}`);
        console.log(`  消息: ${response.data.message}`);
    } catch (error: any) {
        console.log(`  状态码: ${error.response?.status}`);
        console.log(`  响应语言: ${error.response?.headers['content-language']}`);
        console.log(`  错误消息: ${error.response?.data?.message}`);
    }

    // 测试英文
    console.log('\n📝 测试英文 (en):');
    try {
        const response = await axios.post(`${BASE_URL}/auth/wallet-login?lang=en`, {
            walletAddress: wallet.address,
            message: message,
            signature: signature,
            chainId: 1,
            fullName: 'Test User'
        });
        console.log(`  状态码: ${response.status}`);
        console.log(`  响应语言: ${response.headers['content-language']}`);
        console.log(`  消息: ${response.data.message}`);
    } catch (error: any) {
        console.log(`  状态码: ${error.response?.status}`);
        console.log(`  响应语言: ${error.response?.headers['content-language']}`);
        console.log(`  错误消息: ${error.response?.data?.message}`);
    }

    // 测试默认语言
    console.log('\n📝 测试默认语言 (无参数):');
    try {
        const response = await axios.post(`${BASE_URL}/auth/wallet-login`, {
            walletAddress: wallet.address,
            message: message,
            signature: signature,
            chainId: 1,
            fullName: 'Test User'
        });
        console.log(`  状态码: ${response.status}`);
        console.log(`  响应语言: ${response.headers['content-language']}`);
        console.log(`  消息: ${response.data.message}`);
    } catch (error: any) {
        console.log(`  状态码: ${error.response?.status}`);
        console.log(`  响应语言: ${error.response?.headers['content-language']}`);
        console.log(`  错误消息: ${error.response?.data?.message}`);
    }

    console.log('\n✅ i18n 测试完成！');
}

// 运行测试
testI18nMessages().catch(console.error);
